<template>
    <el-row>
        <el-col :md="{span:6,offset:9}" :sm="{span:10,offset: 7}" :xs="{span:18,offset:3}">
            <el-card>
                <el-form label-width="70px" :model="Login" v-loading="loading">
                    <el-form-item label="用户名:">
                        <el-input type="text" v-model="Login.username" />
                    </el-form-item>
                    <el-form-item label="密码:">
                        <el-input type="password" v-model="Login.password" />
                    </el-form-item>
                    <el-form-item>
                        <el-radio v-model="Login.userRole" label="1">系统管理员</el-radio>
                        <el-radio v-model="Login.userRole" label="2">仓库管理员</el-radio>
                        <el-radio v-model="Login.userRole" label="3">医生</el-radio>
                    </el-form-item>
                    <el-form-item >
                        <el-button @click="btnLogin">
                            确认登陆
                        </el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </el-col>
    </el-row>
</template>

<script>
    import utils from "@/Utils";
    export default {
        name: "Login",
        data(){
            return{
                Login:{
                    username:'',
                    password:'',
                    userRole:"3"
                },
                utils,
                loading:false
            }
        },
        methods:{
            btnLogin:function () {
                this.loading=true;
                const login=this.Login;
                const username=login.username
                const password=login.password
                const userRole=login.userRole
                if (utils.isEmpty(username, password, userRole)) {
                    utils.tipsMessage("禁止留空",1)
                    this.loading=false;
                    return
                }
                if(utils.isRange(16,6,username,password)){
                    utils.tipsMessage("用户名密码需要在6~16位之间",1)
                    this.loading=false;
                    return
                }
                if (utils.isSpecialCharacters(username, password)) {
                    utils.tipsMessage("请不要输入除了英文字母数字小数点外的内容",1)
                    this.loading=false;
                    return
                }
                this.axios.post("/User/NotLogin/UserByAccountAndPasswordAndRole",{
                    "UserAccount":username,
                    "UserPassword":password,
                    "UserRole":userRole
                }).then((req)=>{
                    const data=req.data;
                    if(data.code>0){
                        utils.tipsMessage(data.error,data.code);
                        this.loading=false;
                        return
                    }
                    utils.tipsMessage(data.data,data.code);
                    this.loading=false;
                    if(userRole==="1"){
                        this.$router.push("/SystemAdmin/");
                    }else if(userRole==="2"){
                        this.$router.push("/Drugs/");
                    }else {
                        this.$router.push("/Doctor/");
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .el-card{
        margin-top: 20vh;
        min-width: 400px;
    }
    .el-button{
        width: 100%;
    }
</style>